#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int n, m;
int T;
int vis[maxn];
int sa[maxn];
int rk[maxn];
int plen[maxn << 1];
vector<pair<int, int>> adj[maxn];
void add(int u, int v, int w){
    // cerr << u << " " << v << " " << w << endl;
    adj[u].emplace_back(v, w); return ;
}
int dfn[maxn], low[maxn];
int dfsc = 0; int cols = 0;
int col[maxn];
int st[maxn]; int top = 0;
bool inst[maxn];
void tarjan(int now){
    dfn[now] = low[now] = ++dfsc; st[++top] = now; inst[now] = 1;
    for(auto pfr : adj[now]){
	int tt = pfr.first;
	if(dfn[tt] == 0){
	    tarjan(tt); low[now] = min(low[now], low[tt]);
	} else if(inst[tt]){
	    low[now] = min(low[now], dfn[tt]);
	}
    }
    if(dfn[now] == low[now]){
	++cols;
	while(st[top] != now){
	    col[st[top]] = cols; inst[st[top]] = 0; top--;
	}
	col[now] = cols; inst[now] = 0; top--;
    }
    return ;
}
vector<pair<int, int>> adjG[maxn];
int deg[maxn];
bool build(){
    for(int i = 1;i <= n;i++){
	for(auto pfr : adj[i]){
	    int tt = pfr.first;
	    if(pfr.second && col[tt] == col[i]) return 0;
	    if(col[i] != col[tt]){
		adjG[col[tt]].emplace_back(col[i], pfr.second); deg[col[i]]++;
	    }
	}
    }
    return 1;
}
queue<int> qq;
int dis[maxn];
void topo(){
    for(int i = 1;i <= cols;i++){
	if(deg[i] == 0){
	    qq.push(i); dis[i] = 0;
	}
    }
    while(!qq.empty()){
	int fr = qq.front(); qq.pop();
	for(auto pfr : adjG[fr]){
	    int tt = pfr.first; int vv = pfr.second;
	    deg[tt]--; dis[tt] = max(dis[tt], dis[fr] + vv);
	    if(deg[tt] == 0) qq.push(tt);
	}
    }
    return ;
}
int main(){
    freopen("string.in", "r", stdin);
    freopen("string.out", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> T;
    while(T--){
	cin >> n; dfsc = cols = top = 0;
	for(int i = 1;i <= n;i++){
	    vis[i] = 0; adj[i].clear(); dfn[i] = low[i] = dis[i] = deg[i] = col[i] = 0;
	    adjG[i].clear();
	}
	bool fl = 0;
	for(int i = 1;i <= n;i++){
	    int x; cin >> x; x++;
	    if(x > n){
		fl = 1; continue;
	    }
	    if(vis[x]){
		fl = 1; continue;
	    }
	    sa[i] = x; vis[x] = 1; rk[x] = i;
	}
	rk[n + 1] = 0;
	int nowr = 1; int pmid = 1; plen[1] = 1;
	for(int i = 2;i <= 2 * n;i++){
	    cin >> plen[i]; int px = 1;
	    // cerr << plen[i] << " ";
	    if((plen[i] & 1) == (i & 1)){
		// cerr << plen[i] << " " << i << " " << "ok" << endl;
		fl = 1; continue;
	    }
	    if(plen[i] + 1 > i || plen[i] + 1 > 2 * n + 1 - i + 1){
		fl = 1; continue;
	    }
	    if(nowr >= i){
		px = min(plen[2 * pmid - i] + 1, nowr - i + 1);
	    }
	    if(px < nowr - i + 1 && px != plen[i] + 1){
		// cerr << "ok" << endl;
		fl = 1; continue;
	    }
	    while(px < plen[i] + 1){
		if((i + px) % 2 == 0){
		    add((i - px) / 2, (i + px) / 2, 0);
		    add((i + px) / 2, (i - px) / 2, 0);
		}
		px++;
	    }
	    if(i + px - 1 >= nowr){
		nowr = i + px - 1; pmid = i;
	    }
	    // cerr << "? " << i << " " << px << " " << rk[(i - px) / 2] << endl;
	    if(i + px - 1 != n + n + 1 && i - px + 1 != 1){
		if(rk[(i - px) / 2] > rk[(i + px) / 2]) add((i - px) / 2, (i + px) / 2, 1);
		else {
		    add((i + px) / 2, (i - px) / 2, 1);
		}
	    }
	}
	for(int i = 1;i < n;i++){
	    if(rk[sa[i + 1] + 1] < rk[sa[i] + 1]){
		add(sa[i + 1], sa[i], 1);
	    } else {
		add(sa[i + 1], sa[i], 0);
	    }
	}
	for(int i = 1;i <= n;i++){
	    if(dfn[i] == 0) tarjan(i);
	}
	// for(int i = 1;i <= n;i++) cerr << col[i] << " ";
	// cerr << endl;
	if(build() == 0){
	    fl = 1;
	}
	// cerr << fl << endl;
	topo();
	for(int i = 1;i <= n;i++){
	    if(dis[col[i]] >= 26){
		fl = 1; break;
	    }
	}
	if(fl == 1){
	    cout << -1 << '\n'; continue;
	}
	for(int i = 1;i <= n;i++){
	    cout << (char)('a' + dis[col[i]]);
	}
	cout << '\n';
    }
    cout.flush(); return 0;
}
